package com.ljs.ljsstarter.autoConfigure;

/**
 * 自动装配类
 */

import com.ljs.ljsstarter.constant.StarterService;
import com.ljs.ljsstarter.constant.StringPools;
import com.ljs.ljsstarter.properties.LjsConfigProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
//@ConditionalOnClass，当classpath下发现该类的情况下进行自动配置StarterService组件。
@ConditionalOnClass(StarterService.class)
//需要自动配置属性
@EnableConfigurationProperties(LjsConfigProperties.class)
public class AutoConfigure {
    @Resource
    LjsConfigProperties ljsConfigProperties;
    @ConditionalOnMissingBean
    /**
     * matchIfMissing = true ,加这个是配置文件不加ljs.starter.enable也可以配置成功，如果加了，不需要也可以配置成功
     */
    @ConditionalOnProperty(value = "ljs.starter.enable", havingValue = "true", matchIfMissing = true)
    //@ConditionalOnProperty(value = "ljs.starter.enable", havingValue = "true")
     //这里是配置bean的方法,这里也可以集成其他的组件
    @Bean
    StarterService getStarterService(){
        return  new StarterService(ljsConfigProperties.getConfig());
    }



}
